from launch import LaunchDescription
from launch_ros.actions import Node
"""
:param: executable the name of the executable to find if a package
            is provided or otherwise a path to the executable to run.
:param: package the package in which the node executable can be found
:param: name the name of the node
:param: namespace the ROS namespace for this Node
:param: exec_name the label used to represent the process.
    Defaults to the basename of node executable.
:param: parameters list of names of yaml files with parameter rules,
    or dictionaries of parameters.
:param: remappings ordered list of 'to' and 'from' string pairs to be
    passed to the node as ROS remapping rules
:param: ros_arguments list of ROS arguments for the node
:param: arguments list of extra arguments for the node
package  功能包名称
executable 可执行文件名称
namespace  命名空间
exec_name  设置程序标签的 日志 [turtlesim_node-2]
parameters  设置参数
remappings 给话题设置别名
ros_arguments  [] 给节点传参 --ros-args xxx
arguments  [] 给节点传参 xxx --ros-args 
ros2 param dump haha --output-dir ./src/cpp01_launch/config/ 需要节点启动 
--output-dir 这个已经被废弃 用> 重定向代替
 ros2 param dump haha > ./src/cpp01_launch/config/haha_params.yaml
 install(DIRECTORY 
  launch
  config
  DESTINATION share/${PROJECT_NAME})

"""

def generate_launch_description():
    from ament_index_python.packages import get_package_share_directory
    import os
    package_name = 'cpp01_launch'
    # /home/gtd/ros2/ws02_tools/install/cpp01_launch/share/cpp01_launch
    package_share_dir = get_package_share_directory(package_name)
    param_file_path = os.path.join(package_share_dir, 'config', 'haha.yaml')
    print(package_share_dir)
    # t1=Node(package="turtlesim",
    #         executable="turtlesim_node",
    #         name="t1", # 默认 turtlesim
    #         exec_name="my_label",
    #         ros_arguments=['--remap',"__ns:=/t2"], # run xx --ros-args --remap __ns:=/t1
    #         )
    t2=Node(package="turtlesim",
            executable="turtlesim_node",
            name="haha",
            # parameters=[{"background_r":255,"background_g":0,"background_b":0}]
            # parameters=["/home/gtd/ros2/ws02_tools/src/cpp01_launch/config/haha.yaml"]
            parameters=[param_file_path],
            respawn=True  # 是否自动重启
            )
    return LaunchDescription([t2])